local filelog = require "filelog"
local msghelper = require "agenthelper"
local base = require "base"
local playerdatadao = require "playerdatadao"
require "enum"
local filename = "AgentRequest.lua"

local AgentRequest = {}

function AgentRequest.process(session, source, event, ...)
	local f = AgentRequest[event] 
	if f == nil then
		filelog.sys_error(filename.." AgentRequest.process invalid event:"..event)
		base.skynet_retpack(nil)
		return
	end
	f(...)
end

function AgentRequest.gmcmd(cmd, rid, ...)
	local server = msghelper:get_server()
	if rid ~= server.rid then
		base.skynet_retpack(nil)
		return 
	end

	if not msghelper:is_login_success() then
		base.skynet_retpack(nil)
		return		
	end
	local result_data = {issuccess = true}
	if cmd == "player_add_coin" then
		local requestmsg = ...
		msghelper:save_player_coin(rid, requestmsg.coin, EReasonChangeCurrency.CHANGE_CURRENCY_GM_ADD, "player_add_coin")
		msghelper:save_player_gemstone(rid, requestmsg.gemstone, EReasonChangeCurrency.CHANGE_CURRENCY_GM_ADD, "player_add_coin")		
		msghelper:send_gemstonechange_notice()
		base.skynet_retpack(result_data)
		return
	end

	if cmd == "agentmng" then
		local requestmsg = ...
		server.info.agentlevel = requestmsg.agentlevel
		playerdatadao.save_player_info("update", rid, server.info)
		base.skynet_retpack(result_data)
		return		
	end
end

return AgentRequest